<template>
	<view class="page-container">
		<view class="page-title">
			<view class="title-label">阵地名称</view>
			<view class="title-value">{{position_name}}</view>
		</view>
		<view class="form-container">
			<view class="form-card">
				<view class="form-title">维护打击目标的业绩</view>
				<u-form class="main-form" ref="uForm" :border-bottom="false" :label-style="labelStyle">
					<u-form-item :label="item.COMPETITOR_NAME" label-width="auto" v-for="(item,index) in form.COMPETITORINFO">
						<view class="form-item-value"><u-input v-model="item.COMPETITOR_SALES_AMT" type="digit" height="40" :clearable="false" placeholder="请输入金额"/><text>万元</text></view>
					</u-form-item>
				</u-form>
			</view>
		</view>
		<view class="btn-bar">
			<u-button class="submit-btn" shape="circle" :custom-style="btnStyle" :hair-line="false" @click="handleSubmit">提交</u-button>
		</view>
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import { getPositionsInfo, getCompetitorList, savePositionsInfo } from '../../../common/service.js'
	export default {
		data(){
			return {
				isRunning:false,
				labelStyle:{
					fontSize: "28rpx",
					fontFamily: "PingFangSC-Regular, PingFang SC",
					fontWeight: "400",
					color: "#333333",
					lineHeight: "40rpx",
					marginRight:"17rpx"
				},
				labelStyle2:{
					fontSize: "28rpx",
					fontFamily: "PingFangSC-Regular, PingFang SC",
					fontWeight: "400",
					color: "#333333",
					lineHeight: "40rpx",
					marginRight:"50rpx"
				},
				btnStyle:{
					fontSize: "32rpx",
					fontFamily: "PingFangSC-Semibold, PingFang SC",
					fontWeight: "600",
					color: "#FFFFFF",
					letterSpacing: "1px",
					height: "90rpx",
					lineHeight:"90rpx",
					background: "linear-gradient(270deg, #6E7FF3 0%, #4478BF 100%)"
				},
				position_name:"",
				form:{COMPETITORINFO:[]}
			}
		},
		methods:{
			getCompetitorList(pw_id){
				if(!pw_id){
					return
				}
				getCompetitorList({cp_id:pw_id}, res=>{
					if(res.statusCode==200 && !res.data.error_code){
						for(let i of res.data.items){
							this.form.COMPETITORINFO.push({
								PW_M_UKID: null,
								COMPETITOR_NAME: i.competitor_name,
								COMPETITOR_SALES_AMT: "",
								COMPETITOR_AREA: null,
								COMPETITOR_PEPOLE_CNT: null,
								COMPETITOR_NATURE: null,
								COMPETITOR_EVALUATE: null,
								COMPETITOR_CHANNEL: null,
								STATUS: "1"
							})
						}
					}else{
						this.$refs.uToast.show({
							title: res.data.msg,
							type: 'error',
							duration: 3000
						});
					}
				})
			},
			getPositionsInfo(pw_id, m_id, call){
				if(!pw_id || !m_id){
					return
				}
				let params = {
					pw_id,
					m_id
				}
				getPositionsInfo(params, res=>{
					if(res.statusCode==200 && !res.data.error_code){
						if(res.data.items){
							this.form = res.data.items
						}
						if(call){
							call(res.data.items)
						}
					}else{
						this.$refs.uToast.show({
							title: res.data.msg,
							type: 'error',
							duration: 3000
						});
					}
				})
			},
			handleSubmit(){
				if(this.isRunning){
					return
				}
				this.isRunning = true
				for(let i of this.form.COMPETITORINFO){
					if(!i.COMPETITOR_SALES_AMT){
						this.$refs.uToast.show({
							title: "请完整填写维护打击目标的业绩内容",
							type: 'error',
							duration: 3000
						});
						this.isRunning = false
						return
					}
				}
				uni.showLoading({
					title:"操作中...",
					mask:true
				})
				savePositionsInfo({items:this.form}, res=>{
					uni.hideLoading()
					if(res.statusCode==200 && res.data.error_code=="0"){
						this.$refs.uToast.show({
							title: "操作成功",
							type: 'success',
							duration: 3000,
							callback:()=>{
								const eventChannel = this.getOpenerEventChannel()
								eventChannel.emit('reloadList', {})
								uni.navigateBack()
							}
						});
					}else{
						this.isRunning = false
						this.$refs.uToast.show({
							title: res.data.msg,
							type: 'error',
							duration: 3000
						});
					}
				})
			}
		},
		onLoad(options) {
			this.LOGINACTION()
			if(options.title){
				uni.setNavigationBarTitle({
					title:options.title
				})
			}
			
			if(options.name){
				this.position_name = options.name
			}
			if(options.pw_id && options.m_id){
				this.getPositionsInfo(options.pw_id, options.m_id, res=>{
					if(!res){
						this.form.POSITION_ID = options.pw_id
						this.form.MONTH_ID = options.m_id
						this.form.UPDATE_USER = this.CONFIG.user.id
						this.getCompetitorList(options.pw_id)
					}
					
				})
			}
			
		}
	}
</script>

<style>
	uni-page-body{
		padding-bottom: 120rpx;
	}
	.page-container{
		padding: 20rpx 0 0 0;
		background: #F3F5F7;
	}
	.page-title{
		border-radius: 30rpx 30rpx 0px 0px;
		margin-bottom: 10rpx;
		padding: 30rpx 20rpx;
		background-color: #FFFFFF;
	}
	.title-label{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
		line-height: 50rpx;
	}
	.title-value{
		font-size: 32rpx;
		font-family: PingFangSC-Bold, PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 50rpx;
	}
	.form-title{
		padding: 20rpx 20rpx;
		font-size: 30rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #4478BF;
		line-height: 42rpx;
	}
	.form-container{
		background-color: #FFFFFF;
	}
	.form-card{
		padding: 10rpx 0;
	}
	.main-form{
		border-bottom: 1px solid #F2F2F2;
	}
	.main-form .u-form-item{
		padding: 0 30rpx;
		margin-bottom: 20rpx;
	}
	.main-form .form-item-value{
		background: #F7F7F7;
		border-radius: 16rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #9B9B9B;
		line-height: 40rpx;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 20rpx 30rpx 30rpx;
		line-height: 40rpx;
	}
	.list-form-title{
		background: #F0F2F5;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #000000;
		line-height: 40rpx;
		padding: 20rpx 30rpx;
		margin-bottom: 30rpx;
	}
	.list-form .u-form-item{
		display: flex;
		padding: 10rpx 10rpx;
		margin-bottom: 30rpx;
		margin: 0 20rpx 30rpx 20rpx;
		border-bottom: 1px solid #F2F2F2;;
	}
	.list-form .form-item-value{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		line-height: 40rpx;
		flex: 1;
	}
	.list-form .form-item-value .u-input{
		line-height: 40rpx;
		margin-bottom: 1px;
	}
	
	.btn-bar{
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 15rpx 75rpx;
	}
</style>
